import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  //首页
  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "dashboard",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },

  //仓库管理
  {
    path: "/warehouse-management",
    name: "/warehouse-management",
    //redirect: "/system/user",
    meta: {
      title: "仓库管理",
      icon: "warehouse-management",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "InWarehouse",
        component: () =>
          import("@/views/warehouse-management/InWarehouse/index.vue"),
        name: "user", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "入库管理",
          icon: "InWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "OutWarehouse",
        component: () =>
          import("@/views/warehouse-management/OutWarehouse/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "出库管理",
          icon: "OutWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Relocation",
        component: () =>
          import("@/views/warehouse-management/Relocation/index.vue"),
        name: "Relocation", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "移库管理",
          icon: "Relocation",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Pandian",
        component: () => import("@/views/system/Pandian/index.vue"),
        name: "Pandian", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "盘点管理",
          icon: "role",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "allot",
        component: () => import("@/views/system/allot/index.vue"),
        name: "allot", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "调拨管理",
          icon: "homepage",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "breakage",
        component: () => import("@/views/system/breakage/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "报损管理",
          icon: "homepage",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },

  //业务管理
  {
    path: "/business-management",
    name: "/business-management",
    //redirect: "/system/user",
    meta: {
      title: "业务管理",
      icon: "business-management",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "Procurement",
        component: () =>
          import("@/views/warehouse-management/Procurement/index.vue"),
        name: "Procurement", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "入库管理",
          icon: "Procurement",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "OutWarehouse",
        component: () =>
          import("@/views/warehouse-management/OutWarehouse/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "出库管理",
          icon: "OutWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },

  //财务管理
  {
    path: "/financial-management",
    name: "/financial-management",
    //redirect: "/system/user",
    meta: {
      title: "财务管理",
      icon: "financial-management",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "InWarehouse",
        component: () =>
          import("@/views/warehouse-management/InWarehouse/index.vue"),
        name: "user", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "入库管理",
          icon: "InWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "OutWarehouse",
        component: () =>
          import("@/views/warehouse-management/OutWarehouse/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "出库管理",
          icon: "OutWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },

  //报表管理
  {
    path: "/statement-management",
    name: "/statement-management",
    //redirect: "/system/user",
    meta: {
      title: "报表管理",
      icon: "statement-management",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "InWarehouse",
        component: () =>
          import("@/views/warehouse-management/InWarehouse/index.vue"),
        name: "user", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "入库管理",
          icon: "InWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "OutWarehouse",
        component: () =>
          import("@/views/warehouse-management/OutWarehouse/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "出库管理",
          icon: "OutWarehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },

  //基础资料
  {
    path: "/basic-information",
    name: "/basic-information",
    //redirect: "/system/user",
    meta: {
      title: "基础资料",
      icon: "basic-information",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "Warehouse",
        component: () =>
          import("@/views/basic-information/Warehouse/index.vue"),
        name: "Warehouse", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "仓库管理",
          icon: "Warehouse",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "Location",
        component: () => import("@/views/basic-information/Location/index.vue"),
        name: "Location", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "库位管理",
          icon: "Location",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Unit",
        component: () => import("@/views/basic-information/Unit/index.vue"),
        name: "Unit", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "计量单位",
          icon: "Unit",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Supplier",
        component: () => import("@/views/basic-information/Supplier/index.vue"),
        name: "Supplier", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "供应商管理",
          icon: "Supplier",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Customer",
        component: () => import("@/views/basic-information/Customer/index.vue"),
        name: "Customer", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "客户管理",
          icon: "Customer",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "ProductType",
        component: () => import("@/views/BaseService/ProductType/index.vue"),
        name: "ProductType", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "产品类别",
          icon: "ProductType",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
      {
        path: "Product",
        component: () => import("@/views/BaseService/Product/index.vue"),
        name: "Product", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "产品管理",
          icon: "Product",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },

  //系统设置
  {
    path: "/system",
    name: "/system",
    redirect: "/system/user",
    meta: {
      title: "系统管理",
      icon: "system",
      hidden: false,
      roles: ["ADMIN"],
    },
    component: Layout,
    children: [
      {
        path: "user",
        component: () => import("@/views/system/user/index.vue"),
        name: "user", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "用户管理",
          icon: "user",
          hidden: false,
          keepAlive: true,
          roles: ["ADMIN"],
        },
      },
      {
        path: "role",
        component: () => import("@/views/system/role/index.vue"),
        name: "role", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        // https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        meta: {
          title: "角色管理",
          icon: "role",
          hidden: false,
          keepAlive: true,
          roles: ["ROLE"],
        },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
